package com.sh.learn.extjs.service.impl;

import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import javax.annotation.Resource;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;

import com.sh.common.page.QueryResult;
import com.sh.learn.extjs.service.EmployeeService;
import com.sh.learn.extjs.dao.BasicDao;
import com.sh.learn.extjs.domain.Employee;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

@Service("employeeService")
public class EmployeeServiceImpl implements EmployeeService {

	@Resource(name="basicDao")
	private BasicDao<Employee> employeeDao;

	@Transactional(propagation=Propagation.NOT_SUPPORTED, readOnly=true)
	public Employee get(Long id) {
		return employeeDao.findById(Employee.class, id);
	}

	@Transactional(propagation=Propagation.NOT_SUPPORTED, readOnly=true)
	public QueryResult<Employee> list(String scope, Object[] params) {
		LinkedHashMap<String, Object> where = new LinkedHashMap<String, Object>();
		LinkedHashMap<String, String> orderby = new LinkedHashMap<String, String>();
		return employeeDao.getScrollData(Employee.class, where, orderby);
	}

	@Transactional(propagation=Propagation.NOT_SUPPORTED, readOnly=true)
	public QueryResult<Employee> page(String scope, Object[] params, int begin, int max) {
		LinkedHashMap<String, Object> where = new LinkedHashMap<String, Object>();
		LinkedHashMap<String, String> orderby = new LinkedHashMap<String, String>();
		return employeeDao.getScrollData(Employee.class, begin, max, where, orderby);
	}

	@Transactional(propagation=Propagation.REQUIRED)
	public Long add(Employee e) throws Exception {
		employeeDao.insert(e);
		return e.getId();
	}

	@Transactional(propagation=Propagation.REQUIRED)
	public void update(Employee e) throws Exception {
		employeeDao.update(e);
	}

	@Transactional(propagation=Propagation.REQUIRED)
	public void remove(Long id) throws Exception {
		employeeDao.deleteById(Employee.class, id);
	}


	public BasicDao<Employee> getEmployeeDao() {
		return employeeDao;
	}

	public void setEmployeeDao(BasicDao<Employee> employeeDao) {
		this.employeeDao = employeeDao;
	}

}
